import { Entity, Column } from 'typeorm';
import { BaseEntity } from '../../../common/base.entity';
import { omit } from 'lodash';

@Entity('base_sys_user', { schema: 'midway-admin' })
export class UserEntity extends BaseEntity {
  @Column('int', { name: 'deptId', nullable: true, comment: '部门ID' })
  deptId: number | null;

  @Column('varchar', { name: 'userName', comment: '用户名', length: 100 })
  userName: string;

  @Column('varchar', { name: 'password', comment: '密码', length: 255 })
  password: string;

  @Column('varchar', {
    name: 'name',
    nullable: true,
    comment: '姓名',
    length: 255,
  })
  name: string | null;

  @Column('varchar', {
    name: 'nickName',
    nullable: true,
    comment: '昵称',
    length: 255,
  })
  nickName: string;

  @Column('varchar', {
    name: 'headImg',
    nullable: true,
    comment: '头像',
    length: 255,
  })
  headImg: string;

  @Column('varchar', {
    name: 'phone',
    nullable: true,
    comment: '手机',
    length: 20,
  })
  phone: string | null;

  @Column('varchar', {
    name: 'email',
    nullable: true,
    comment: '邮箱',
    length: 255,
  })
  email: string | null;

  @Column('varchar', {
    name: 'remark',
    nullable: true,
    comment: '备注',
    length: 255,
  })
  remark: string | null;

  @Column('boolean', {
    name: 'status',
    comment: '用户启用状态',
    default: true,
  })
  status: number;

  @Column('json', { name: 'roleList', nullable: true, comment: '角色权限' })
  roleList: object;

  toVO() {
    const userVO = omit<UserEntity>(this, ['password']);
    return userVO;
  }
}
